﻿
using KouDai.Phone.Engine;
using System;
namespace KouDai.Phone.Parsers
{
    public abstract class BaseParser
    {
        protected BaseParser _nextParser;

        public BaseParser NextParser
        {
            get { return _nextParser; }
            set { _nextParser = value; }
        }

        public void ParseJson(string json, BackData backData)
        {
            if (!string.IsNullOrEmpty(json) && backData != null && backData.ResposeData != null)
            {
                try
                {
                    ParseData(json, backData);
                }
                catch (Exception ex)
                {
                    backData.IsSuccess = false;
                    backData.Msg = "Parse error: " + ex.Message.ToString();
                }
            }
            else
            {
                backData.IsSuccess = false;
                backData.Msg = "backdata is null or backdata.respoonseData is null.";
            }
            if (this._nextParser != null)
            {
                this._nextParser.ParseJson(json, backData);
            }
        }

        public abstract void ParseData(string json, BackData backData);
    }
}
